package com.project.slsx.utils;

import android.support.annotation.LayoutRes;
import android.support.v4.app.FragmentManager;

import com.project.slsx.R;
import com.project.slsx.widget.dialog.BaseNiceDialog;
import com.project.slsx.widget.dialog.NiceDialog;
import com.project.slsx.widget.dialog.ViewConvertListener;


public class DialogUtils {

    private static BaseNiceDialog dialog;
    private boolean outCancel = false;

    public static void showDialog(@LayoutRes int layoutId,
                                  int width,
                                  int height,
                                  boolean outCancel,
                                  ViewConvertListener listener,
                                  FragmentManager fragmentManager) {
        dialog = NiceDialog.init()
                .setLayoutId(layoutId)
                .setConvertListener(listener)
                .setWidth(width)
                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(outCancel)
//                .setAnimStyle(R.style.EnterExitAnimation)
                .show(fragmentManager);
    }

    public static BaseNiceDialog showDialog(@LayoutRes int layoutId,
                                            int width,
                                            int height,
                                            boolean outCancel,
                                            ViewConvertListener listener
                                  ) {
        dialog = NiceDialog.init()
                .setLayoutId(layoutId)
                .setConvertListener(listener)
                .setWidth(width)
                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(outCancel);
//                .setAnimStyle(R.style.EnterExitAnimation)
        return dialog;
    }

    public static void showDialog(@LayoutRes int layoutId,
                                  int width,
                                  boolean outCancel,
                                  ViewConvertListener listener,
                                  FragmentManager fragmentManager) {
        dialog = NiceDialog.init()
                .setLayoutId(layoutId)
                .setConvertListener(listener)
                .setWidth(width)
//                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(outCancel)
//                .setAnimStyle(R.style.EnterExitAnimation)
                .show(fragmentManager);
    }

    public static void showLoading(ViewConvertListener listener,
                                   FragmentManager fragmentManager) {
        dialog = NiceDialog.init()
                .setLayoutId(R.layout.dialog_loading2)
                .setConvertListener(listener)
                .setWidth(-1)
//                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(false)
//                .setAnimStyle(R.style.EnterExitAnimation)
                .show(fragmentManager);
    }

    public static void showLoading(FragmentManager fragmentManager) {
        dialog = NiceDialog.init()
                .setLayoutId(R.layout.dialog_loading2)
                .setConvertListener(null)
                .setWidth(-1)
//                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(false)
//                .setAnimStyle(R.style.EnterExitAnimation)
                .show(fragmentManager);
    }

    public static BaseNiceDialog showLoadingView() {
        dialog = NiceDialog.init()
                .setLayoutId(R.layout.dialog_loading2)
                .setConvertListener(null)
                .setWidth(-1)
//                .setHeight(height)
                .setDimAmount(0.5f)
                .setOutCancel(false);
//                .setAnimStyle(R.style.EnterExitAnimation);
        return dialog;
    }

    public static void dissmissDialog() {
        if (dialog != null && dialog.isVisible()) {
            dialog.dismiss();
            dialog = null;
        }
    }
}
